package com.sec.android.app.myfiles.module;

import android.content.Context;

import com.sec.android.app.myfiles.decorator.tablet.TabletMenuImpDecorator;
import com.sec.android.app.myfiles.facade.FacadeItem;
import com.sec.android.app.myfiles.facade.cmd.CompressRecordsCmd;
import com.sec.android.app.myfiles.facade.cmd.ContactUsCmd;
import com.sec.android.app.myfiles.facade.cmd.ConvertCmd;
import com.sec.android.app.myfiles.facade.cmd.CopyMoveCmd;
import com.sec.android.app.myfiles.facade.cmd.CreateDirCmd;
import com.sec.android.app.myfiles.facade.cmd.CreateDocumentCmd;
import com.sec.android.app.myfiles.facade.cmd.DecompressRecordsCmd;
import com.sec.android.app.myfiles.facade.cmd.DeleteRecordCmd;
import com.sec.android.app.myfiles.facade.cmd.ExecuteRecordCmd;
import com.sec.android.app.myfiles.facade.cmd.FinishPickerCmd;
import com.sec.android.app.myfiles.facade.cmd.GoHomeBlankCmd;
import com.sec.android.app.myfiles.facade.cmd.GoHomeCmd;
import com.sec.android.app.myfiles.facade.cmd.GoPrivateFolderRootCmd;
import com.sec.android.app.myfiles.facade.cmd.GoSettingsCmd;
import com.sec.android.app.myfiles.facade.cmd.GoTrashCmd;
import com.sec.android.app.myfiles.facade.cmd.ImportFromAppsCmd;
import com.sec.android.app.myfiles.facade.cmd.LaunchPickerCmd;
import com.sec.android.app.myfiles.facade.cmd.LockUnlockCmd;
import com.sec.android.app.myfiles.facade.cmd.MoveKnoxModeCmd;
import com.sec.android.app.myfiles.facade.cmd.MoveToPrivateCmd;
import com.sec.android.app.myfiles.facade.cmd.MoveToPrivateFolderCmd;
import com.sec.android.app.myfiles.facade.cmd.ReloadCmd;
import com.sec.android.app.myfiles.facade.cmd.RemoveFromPrivateFolderCmd;
import com.sec.android.app.myfiles.facade.cmd.RenameHomeItemCmd;
import com.sec.android.app.myfiles.facade.cmd.RenameRecordCmd;
import com.sec.android.app.myfiles.facade.cmd.SetSortByCmd;
import com.sec.android.app.myfiles.facade.cmd.ShareViaCmd;
import com.sec.android.app.myfiles.facade.cmd.ShowDetailCmd;
import com.sec.android.app.myfiles.facade.cmd.ShowHiddenFileCmd;
import com.sec.android.app.myfiles.facade.cmd.ShowNotEnoughStorageCmd;
import com.sec.android.app.myfiles.facade.cmd.ShowRecentFilesCmd;
import com.sec.android.app.myfiles.facade.cmd.SpinnerProgressCmd;
import com.sec.android.app.myfiles.facade.cmd.ToSelectModeCmd;
import com.sec.android.app.myfiles.fragment.AbsMyFilesFragment;
import com.sec.android.app.myfiles.fragment.home.HomeFragment;
import com.sec.android.app.myfiles.fragment.home.HomeFragmentItem;
import com.sec.android.app.myfiles.info.AppFeatures;
import com.sec.android.app.myfiles.module.abstraction.AbsContentObserverImp;
import com.sec.android.app.myfiles.module.abstraction.AbsDragAndDrop;
import com.sec.android.app.myfiles.module.abstraction.AbsFileListAdapterImp;
import com.sec.android.app.myfiles.module.abstraction.AbsFileOperationImp;
import com.sec.android.app.myfiles.module.abstraction.AbsModuleLoaderImp;
import com.sec.android.app.myfiles.module.abstraction.AbsProviderImp;
import com.sec.android.app.myfiles.module.abstraction.AbsReloadStrategyImp;
import com.sec.android.app.myfiles.module.abstraction.FileRecord;
import com.sec.android.app.myfiles.module.abstraction.FileRecord.StorageType;
import com.sec.android.app.myfiles.module.abstraction.IMenuImp;
import com.sec.android.app.myfiles.navigation.NavigationInfo;
import com.sec.android.app.myfiles.operation.ProgressListener;
import com.sec.android.app.myfiles.provider.DbTableInfo;
import com.sec.android.app.myfiles.widget.listview.AbsListViewImp;

import java.util.ArrayList;

public class ModuleLoader {
    AbsModuleLoaderImp mModuleLoaderImp;
    ModuleManager mModuleManager;

    static ModuleLoader mSelf = null;


    private ModuleLoader() {
        mModuleManager = ModuleManager.getModuleManager();
        mModuleLoaderImp = mModuleManager.getModules();
    }

    public static ModuleLoader getInstance() {
        if (mSelf == null) {
            mSelf = new ModuleLoader();
        }
        return mSelf;
    }

    public FileRecord createFileRecord(StorageType storageType, String fullPath) {
        return mModuleLoaderImp.createFileRecord(storageType, fullPath);
    }

    public FileRecord createFileRecord(StorageType storageType, int id, String path, String name, long size, long date, int fileType,
                                       int isHidden, int itemCount, int itemCountHidden) {
        return mModuleLoaderImp.createFileRecord(storageType, id, path, name, size, date, fileType, isHidden, itemCount, itemCountHidden);
    }

    public AbsFileListAdapterImp createAdapterImp(NavigationInfo navigationInfo, Context context, AbsListViewImp listView) {
        return mModuleLoaderImp.createAdapterImp(navigationInfo, context, listView);
    }

    public AbsProviderImp createProviderImp(Context context) {
        return mModuleLoaderImp.createProviderImp(context, null);
    }

    public DbTableInfo getTableInfo(FileRecord.StorageType storageType) {
        return mModuleLoaderImp.getTableInfo(storageType);
    }

    public IMenuImp createMenuImp(Context context, StorageType storageType) {
        IMenuImp ret = mModuleLoaderImp.createMenuImp(context, storageType);
        if (ret != null && AppFeatures.isTabletUIMode()) {
            ret = new TabletMenuImpDecorator(context, ret);
        }
        return ret;
    }

    public AbsFileOperationImp createFileOperationImp(Context context, ProgressListener listener) {
        return mModuleLoaderImp.createFileOperationImp(context, listener, null);
    }

    public AbsDragAndDrop createDragAndDropImp(AbsMyFilesFragment fragment, StorageType storageType, AbsListViewImp listViewImp) {
        return mModuleLoaderImp.createDragAndDropImp(fragment, storageType, listViewImp);
    }

    public void createHomeItem(Context context, HomeFragment fragment, ArrayList<HomeFragmentItem> itemList, boolean isLeftPanel) {
        mModuleLoaderImp.createHomeItem(context, fragment, itemList, isLeftPanel);
    }

    public AbsContentObserverImp createContentObserver(Context context, FileRecord record, ContentObservable updater) {
        return mModuleLoaderImp.createContentObserver(context, record, updater);
    }

    public AbsReloadStrategyImp createReloadStrategy(Context context, NavigationInfo navigationInfo) {
        if (navigationInfo == null) {
            return null;
        }
        return mModuleLoaderImp.createReloadStrategy(context, navigationInfo);
    }

    public ArrayList<FacadeItem> getFacadeItemList() {
        ArrayList<FacadeItem> ret = new ArrayList<>();

        ret.add(FacadeItem.createFacadeItem(FacadeItem.EXECUTE_RECORD, new ExecuteRecordCmd()));
        ret.add(FacadeItem.createFacadeItem(FacadeItem.GO_HOME, new GoHomeCmd()));
        ret.add(FacadeItem.createFacadeItem(FacadeItem.GO_HOME_BLANK, new GoHomeBlankCmd()));
		ret.add(FacadeItem.createFacadeItem(FacadeItem.GO_PRIVATE_ROOT, new GoPrivateFolderRootCmd()));
        ret.add(FacadeItem.createFacadeItem(FacadeItem.LAUNCH_PICKER, new LaunchPickerCmd()));
        ret.add(FacadeItem.createFacadeItem(FacadeItem.FINISH_PICKER, new FinishPickerCmd()));
        ret.add(FacadeItem.createFacadeItem(FacadeItem.SHOW_HIDDEN_FILE, new ShowHiddenFileCmd()));
        ret.add(FacadeItem.createFacadeItem(FacadeItem.SELECT_MODE, new ToSelectModeCmd()));
        ret.add(FacadeItem.createFacadeItem(FacadeItem.COPY_MOVE, new CopyMoveCmd()));
        ret.add(FacadeItem.createFacadeItem(FacadeItem.MOVE_TO_PRIVATE, new MoveToPrivateCmd()));
        ret.add(FacadeItem.createFacadeItem(FacadeItem.DELETE_RECORD, new DeleteRecordCmd()));
        ret.add(FacadeItem.createFacadeItem(FacadeItem.RENAME_RECORD, new RenameRecordCmd()));
        ret.add(FacadeItem.createFacadeItem(FacadeItem.CREATE_DIR, new CreateDirCmd()));
        ret.add(FacadeItem.createFacadeItem(FacadeItem.SET_SORT_BY, new SetSortByCmd()));
        ret.add(FacadeItem.createFacadeItem(FacadeItem.SHOW_DETAIL, new ShowDetailCmd()));
        ret.add(FacadeItem.createFacadeItem(FacadeItem.SHARE_VIA, new ShareViaCmd()));
        ret.add(FacadeItem.createFacadeItem(FacadeItem.CONVERT, new ConvertCmd()));
        ret.add(FacadeItem.createFacadeItem(FacadeItem.RELOAD, new ReloadCmd()));
        ret.add(FacadeItem.createFacadeItem(FacadeItem.COMPRESS_RECORDS, new CompressRecordsCmd()));
        ret.add(FacadeItem.createFacadeItem(FacadeItem.DECOMPRESS_RECORDS, new DecompressRecordsCmd()));
        ret.add(FacadeItem.createFacadeItem(FacadeItem.LOCK_UNLOCK, new LockUnlockCmd()));
        ret.add(FacadeItem.createFacadeItem(FacadeItem.SPINNER_PROGRESS, new SpinnerProgressCmd()));
        ret.add(FacadeItem.createFacadeItem(FacadeItem.MOVE_KNOX_MODE, new MoveKnoxModeCmd()));
        ret.add(FacadeItem.createFacadeItem(FacadeItem.CREATE_DOCUMENT, new CreateDocumentCmd()));
        ret.add(FacadeItem.createFacadeItem(FacadeItem.IMPORT_FROM_APP, new ImportFromAppsCmd()));
        ret.add(FacadeItem.createFacadeItem(FacadeItem.RENAME_HOME_ITEM, new RenameHomeItemCmd()));
        ret.add(FacadeItem.createFacadeItem(FacadeItem.CONTACT_US, new ContactUsCmd()));
        ret.add(FacadeItem.createFacadeItem(FacadeItem.GO_SETTINGS, new GoSettingsCmd()));
        ret.add(FacadeItem.createFacadeItem(FacadeItem.GO_TRASH, new GoTrashCmd()));
        ret.add(FacadeItem.createFacadeItem(FacadeItem.SHOW_NOT_ENOUGH_STORAGE, new ShowNotEnoughStorageCmd()));
        ret.add(FacadeItem.createFacadeItem(FacadeItem.SHOW_RECENT_FILES, new ShowRecentFilesCmd()));
        ret.add(FacadeItem.createFacadeItem(FacadeItem.MOVE_TO_PRIVATE_FOLDER, new MoveToPrivateFolderCmd()));
        ret.add(FacadeItem.createFacadeItem(FacadeItem.REMOVE_FROM_PRIVATE_FOLDER, new RemoveFromPrivateFolderCmd()));


        mModuleLoaderImp.addFacadeItemList(ret);

        return ret;
    }

}
